package com.sq.system.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.sq.system.mapper.SysLoginLogMapper;
import com.sq.system.pojo.SysLoginLog;
import com.sq.system.pojo.SysOperLog;
import com.sq.system.service.SysLoginLogService;
import com.sq.system.vo.SysOperLogVo;
import com.sq.system.vo.ThreadShare;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;


/**
 *
 */
@Service
public class SysLoginLogServiceImpl extends ServiceImpl<SysLoginLogMapper, SysLoginLog>
    implements SysLoginLogService
{

    @Autowired
    private SysLoginLogMapper sysLoginLogMapper;



    @Override
    public int saveLoginLog(SysLoginLog sysLoginLogDto) {
        // bean 转换
        SysLoginLog sysLoginLog = new SysLoginLog();
        BeanUtils.copyProperties(sysLoginLogDto,sysLoginLog);
        sysLoginLog.setLogId(IdWorker.getIdStr());
        boolean save = save(sysLoginLog);
        return save ? 1 : 0;
    }

    @Override
    public List<SysLoginLog> selectLoginLogList(SysLoginLog sysLoginLog) {
        return sysLoginLogMapper.selectWhere(sysLoginLog);
    }

    /**
     * 查询操作日志
     * @param sysOperLog
     * @return
     */
    @Override
    public List<SysLoginLog> selectSysOperLog(SysOperLog sysOperLog) {
//        String[] esSearchFiled = getEsSearchFiled(sysOperLog.getClass());
//        SearchResponse searchResponse = elasticSearchCompositeTemplete.searchByPage(SysOperLog.es_index, sysOperLog, sysOperLog.getPageNum(), sysOperLog.getPageSize(), esSearchFiled, null);
//        SearchHits hits = searchResponse.getHits();
//        int totalShards = searchResponse.getTotalShards();
        return null;
    }

    @Override
    public ThreadShare selectSysOperLogReturnShare(SysOperLog sysOperLog) {
//        String[] esSearchFiled = getEsSearchFiled(sysOperLog.getClass());
//        ThreadShare threadShare = new ThreadShare();
//        SearchResponse searchResponse = elasticSearchCompositeTemplete.searchByPage(SysOperLog.es_index, sysOperLog, sysOperLog.getPageNum(), sysOperLog.getPageSize(), esSearchFiled, null);
//        SearchHits hits = searchResponse.getHits();
//        ArrayList<SysOperLogVo> sysOperLogVos = new ArrayList<>();
//        for (SearchHit searchHit : hits){
//            String sourceAsString = searchHit.getSourceAsString();
//            SysOperLogVo logVo = JSONUtil.toBean(sourceAsString, SysOperLogVo.class);
//            sysOperLogVos.add(logVo);
//        }
//        long totalHits = searchResponse.getHits().getTotalHits().value;
//        long totalShards = searchResponse.getTotalShards();
//        threadShare.setTotal(totalHits);
//        threadShare.setRecordList(sysOperLogVos);
//        return threadShare;
        return null;
    }

    @Override
    public Long selectCount(SysOperLog sysOperLog) {
//        Long count = elasticSearchCompositeTemplete.getCount(SysOperLog.es_index);
        return 0L;
    }
}




